package com.ycode.bang.anbang.utils;

import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringUtils {
	
	

	public static boolean isHttp(String str) {
		if (str != null && str.length() > 0) {
			if (str.startsWith("http") || str.startsWith("https")) {
				return true;
			}
		}
		return false;
	}

	public static boolean isEmpty(String str) {
		return str == null || str.length() <= 0 || str.equals("null");
	}

	/**
	 * �?��邮箱地址是否合法
	 * 
	 * @param email
	 * @return true合法 false不合�?
	 */
	public static boolean isEmail(String email) {
		if (null == email || "".equals(email))
			return false;
		// Pattern p = Pattern.compile("\\w+@(\\w+.)+[a-z]{2,3}"); //�?��匹配
		Pattern p = Pattern
				.compile("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");// 复杂匹配
		Matcher m = p.matcher(email);
		return m.matches();
	}
	/**
	 * 手机校验
	 * 
	 * @param phone
	 * @return true合法 false不合�?
	 */
	public static boolean isPhone(String phone) {
		if (null == phone || "".equals(phone))
			return false;
		// Pattern p = Pattern.compile("\\w+@(\\w+.)+[a-z]{2,3}"); //�?��匹配
		Pattern p = Pattern
				.compile("[1][3578]\\d{9}");// 复杂匹配
		Matcher m = p.matcher(phone);
		return m.matches();
	}
	/**
	 * 密码格式校验
	 * 
	 * @param phone
	 * @return true合法 false不合�?
	 */
	public static boolean isPassword(String phone) {
		if (null == phone || "".equals(phone)||phone.length()<6)
			return false;
		Pattern p = Pattern
				.compile("^.*[A-Za-z0-9\\w_-]+.*$");// 复杂匹配
		Matcher m = p.matcher(phone);
		return m.matches();
	}
	/**
	 * 时间转换成时间戳
	 * @param str_time
	 * @return
	 */
	public static String getTime(String str_time){
		String re_time = "";
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Date d;
		try {
			d = sdf.parse(str_time);
			long l = d.getTime();
			String str = String.valueOf(l);
			re_time = str.substring(0, 10);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return re_time;
		
	}
	
	 public static String getDateToString(long time) {
         Date d = new Date(time);
         SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
         return sf.format(d);
     }

	/**
	 * 判断是否是文件
	 * @param value
	 * @return
	 */
	public static boolean isFile(String value) {
		if (StringUtils.isEmpty(value)) {
			return false;
		}

//		if(StringUtils.isHttp(value)){
//			return false;
//		}

		File file = new File(value);
		if (file.exists() && file.isFile()) {
			return true;
		}
		return false;
	}


}
